<template>
  <div id="app">
    <!-- <img src="./assets/logo.png"> -->
    <transition name="fade" mode="out-in" v-if="isRouterAlive">
      <router-view></router-view>
    </transition>
  </div>
</template>

<script>
import bus from './api/bus.js'
import { removeLogoutFlag } from '@/utils/auth'
import { setLocalStorage, getLocalStorage } from '@/utils/localStorage' // setLocalStorage, getLocalStorage, removeLocalStorage
export default {
  name: 'App',
  provide() {
    return {
      reload: this.reload
    }
  },
  data() {
    return {
      isRouterAlive: true
    }
  },
  created() {
    // 当token失效后，会执行此段代码
    bus.$off('toLoginPage')
    bus.$on('toLoginPage', () => {
      this.logout()
    })
    // 监听模拟键盘按键被按下弹起事件
    bus.$off('tiggerKeyupEvent')
    bus.$on('tiggerKeyupEvent', () => {
      this.tiggerKeyupEvent()
    })
    setTimeout(() => {
      bus.$emit('tiggerKeyupEvent')
    }, 5000)
  },
  beforeDestroy() {
    bus.$off('toLoginPage')
    bus.$off('tiggerKeyupEvent')
    window.removeEventListener('beforeunload')
    window.removeEventListener('message', this.addSaveArea, false)
  },
  mounted() {
    // 刷新或者关闭页面清空操作时间和清空是否退出登录的判断
    window.addEventListener('beforeunload', () => {
      removeLogoutFlag()
      // removeOperateTime()
    })
    window.addEventListener('message', this.addSaveArea)
  },
  methods: {
    addSaveArea(e) {
      let ed = e.data || {}
      if (ed.type == 'saveClientAreaName') {
        let string = getLocalStorage('localSetMemory') || `{"modalitytype":"","depArea":"","areaName":"","dep":""}`
        let localSetMemoryObj = JSON.parse(string)
        localSetMemoryObj.areaName = ed.data.value
        setLocalStorage('localSetMemory', JSON.stringify(localSetMemoryObj))
        window.location.reload(true)
      }
    },
    tiggerKeyupEvent() {
      document.getElementById('app').dispatchEvent(new KeyboardEvent('keyup', { keyCode: 98 }))
    },
    async logout() {
      await this.$store.dispatch('user/logout')
      this.$router.push(`/login`)
    },
    reload() {
      this.isRouterAlive = false
      this.$nextTick(function () {
        this.isRouterAlive = true
      })
    }
  },
  components: {}
}
</script>

<style lang="scss">
@import "~scss_index";
@import "~scss_vars";
@import url('./styles/ElementUISmall.css');
body {
  margin: 0px;
  padding: 0px;
  font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB,
    Microsoft YaHei, SimSun, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
#app {
  width: 100%;
  position: absolute;
  top: 0px;
  bottom: 0px;
}
.el-submenu [class^="fa"] {
  vertical-align: -1px;
  margin-right: 10px;
}
.el-menu-item [class^="fa"] {
  vertical-align: baseline;
  margin-right: 10px;
}
.menu_icon{
  width: 22px;
}
.toolbar {
  font: 14px "微软雅黑";
  color: $color-primary;
  background: #f2f2f2;
  padding: 10px 15px;
  margin: 10px 0px;
  .el-form-item {
    margin-bottom: 10px;
  }
}
.headTip {
  padding: 10px 15px;
  margin: 10px auto;
  font: 14px "微软雅黑";
  color: #fff;
  background: $color-primary;
}
.fade-enter-active,
.fade-leave-active {
  transition: all 0.2s ease;
}
.fade-enter,
.fade-leave-active {
  opacity: 0;
}
/*滚动条*/
::-webkit-scrollbar-track-piece {
  background-color: #fff;
}

::-webkit-scrollbar {
  width: 13px;
  height: 13px;
}
::-webkit-scrollbar-button{
  display: none;
}

::-webkit-scrollbar-thumb {
  background-color: #ccc;
  background-clip: padding-box;
  min-height: 28px;
}

::-webkit-scrollbar-thumb:hover {
  background-color: #ddd;
}
/* 公用样式 */
/* flex布局 */
.scroll-y{
  overflow-y: scroll;
}

.flex{
  display: flex;
}
.flex-1 {
  flex: 1 !important;
}
.flex-2 {
  flex: 2;
}
.flex-3 {
  flex: 3;
}
.flex-4 {
  flex: 4;
}
.flex-5 {
  flex: 5;
}
.flex-row{
  flex-direction: row !important;
}
.flex-column{
  flex-direction: column;
}
.flex-wrap{
  flex-wrap: wrap;
}
.flex-fill {
  -ms-flex: 1 1 auto !important;
  flex: 1 1 auto !important;
}
.align-top{
  vertical-align:top;
}
.align-start{
  align-items: flex-start; /*元素位于容器的开头。*/
}
.align-end{
  align-items: flex-end; /*元素位于容器底部*/
}
.align-center{
   align-items: center; /*垂直居中*/
}
.justify-around{
  justify-content: space-around;
}
.justify-between{
  justify-content: space-between;
}
.justify-center {
  justify-content: center;
}
.justify-start {
  justify-content: flex-start;
}
.justify-end {
  justify-content: flex-end !important;
}
.f-r {
  float: right;
}
.f-l {
  float: left;
}
/* 文本居中/居左/居右 */
.text-center {
  text-align: center;
}
.text-left {
  text-align: left;
}
.text-right {
  text-align: right;
}
.text-middle{
  vertical-align: middle;
}
.pad-b-6{
  padding-bottom: 6px;
}
.pad-b-10{
  padding-bottom: 10px;
}
.pad-l-10{
  padding-left: 10px;
}
.mar-l-3{
  margin-left: 3px !important;
}
.mar-l-5{
  margin-left: 5px !important;
}
.mar-l-6{
  margin-left: 6px !important;
}
.mar-l-8 {
  margin-left: 8px !important;
}
.mar-l-10 {
  margin-left: 10px !important;
}
.mar-l-15 {
  margin-left: 15px !important;
}
.mar-l-20 {
  margin-left: 20px !important;
}
.mar-l-30 {
  margin-left: 30px !important;
}

.mar-r-3 {
  margin-right: 3px !important;
}
.mar-r-5 {
  margin-right: 5px !important;
}
.mar-r-6 {
  margin-right: 6px !important;
}
.mar-r-10 {
  margin-right: 10px !important;
}

.mar-t-3{
  margin-top: 3px !important;
}
.mar-t-6{
  margin-top: 6px !important;
}
.mar-t-8 {
  margin-top: 8px !important;
}
.mar-t-10 {
  margin-top: 10px !important;
}
.mar-t-20 {
  margin-top: 20px !important;
}

.font-bold {
  font-weight: bold;
}

.fs-8{ font-size: 8px; }
.fs-9{ font-size: 9px; }
.fs-10{ font-size: 10px; }
.fs-11{ font-size: 11px; }
.fs-12{ font-size: 12px; }
.fs-13{ font-size: 13px; }
.fs-14{ font-size: 14px; }
.fs-15{ font-size: 15px; }
.fs-16{ font-size: 16px; }
.fs-18{ font-size: 18px; }
.fs-20{ font-size: 20px; }
.fs-22{ font-size: 22px; }
.fs-24{ font-size: 24px; }
.fs-30{ font-size: 30px; }

.w-100 {
  width: 100%;
}
.h-100 {
  height: 100%;
}

.red{
  color: #ff5500;
}
.c666{
  color: #666;
}

.noSelect{
  user-select: none;
}

.dis-block{
  display: block;
}
.dis-inline-block{
  display: inline-block;
}

.pos-rel {
  position: relative;
}

.pos-abs {
  position: absolute;
}

.pos-fixed {
  position: fixed;
}

.hide{
  display: none;
}
.over-hid {
  overflow: hidden;
}

.cursor-pointer {
  cursor: pointer;
}

.ellipsis-text-line1 {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  line-clamp: 1;
}

.cont_box{
  /* height: calc(100vh - 98px); */
  height: calc(95vh - 113px);
  /* padding: 16px 24px; */
  padding: 19px 19px;
  overflow-y: auto;
}

.buttons{
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background: #fff;
  padding: 12px 12px;
  border-top: 1px solid #E5E7EC;
  z-index: 1;
  /deep/ .el-form-item__content{
    width:100%
  }
  .btn_checkall{
    float: left;
  }
  .left-buttons{
    float:left;
  }
  .right-buttons{
    float:right
  }
  .el-dropdown{
    color: #00c0ef;
  }
}
.total_s{
  font-size: 12px;
  width: 100%;
  line-height: 1.8em;
  .span_num{
    float: right;
    font-weight: bold;
  }
}
</style>
